<?php

namespace app\api\controller\user;

use app\api\controller\Controller;
use app\api\model\user\MoneyLog as MoneyLogModel;
use app\api\model\user\PointsLog as PointsLogModel;
use app\api\model\user\BalanceLog as BalanceLogModel;
use app\api\model\user\DealerLog as DealerLogModel;
use app\api\model\dealer\User as DealerUserModel;
use think\Db;
class Log extends Controller
{
    /* @var \app\api\model\User $user */
    protected $user;

    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->user = $this->getUser();   // 用户信息
    }

    /**
     * 余额变更记录
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function moneylog()
    {
        $param = $this->request->post();
        $model = new MoneyLogModel;
        $list = $model->getList($this->user['user_id'],$param['page']);
        $money = $this->user['money']?:0;
        return $this->renderSuccess(compact('money','list'));

    }


    /**
     * 积分变更记录
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function pointslog()
    {
        $param = $this->request->post();
        $model = new PointsLogModel;
        $list = $model->getList($this->user['user_id'],$param['page']);
        $userpoints = $this->user['points']?:0;
        return $this->renderSuccess(compact('userpoints','list'));

    }


    /**
     * 零钱变更记录
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function balancelog()
    {
        $param = $this->request->post();
        $model = new BalanceLogModel;
        $list = $model->getList($this->user['user_id'],$param['page']);
        $userbalance = $this->user['balance']?:0;
        return $this->renderSuccess(compact('userbalance','list'));

    }


    /**
     * 收益余额变更记录
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function dealerlog()
    {
        //获取提现是否需要获取手机号
        $res=Db::name('user')->where(['user_id'=>$this->user['user_id']])->find();
        if($res['mobile']){
            $dealer['isAuth'] = true;
        }else{
            $dealer['isAuth'] = false;
        }
        $data = DealerUserModel::detail($this->user['user_id'],$this->wxapp_id);
        //可提现
        $dealer['money'] = $data['money']?:0;
        $dealer['freeze_money'] = $data['freeze_money']?:0;
        $dealer['total_money'] = $data['total_money']?:0;

        return $this->renderSuccess(compact('dealer'));

    }



    /**
     * 明细记录
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function detaillog()
    {
        $param = $this->request->post();
        $model = new DealerLogModel;
        $list = $model->getList($this->user['user_id'],$param['page'],$param['type']);
        return $this->renderSuccess($list);

    }

}